package cn.bdqn.service.impl;

import cn.bdqn.mapper.BasDictMapper;
import cn.bdqn.pojo.BasDict;
import cn.bdqn.service.BasDictService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BasDictServiceImpl implements BasDictService {
    @Resource
    BasDictMapper basDictMapper;
    @Override
    public List<BasDict> getDictByDictType(String dictType) {
        QueryWrapper<BasDict> qw=new QueryWrapper<>();
        qw.eq("dict_type",dictType);
        return basDictMapper.selectList(qw);
    }

    @Override
    public IPage<BasDict> getDictsByPage(String dictType, String dictItem, Integer pageNo, Integer pageSize) {
        //组装分页条件
        Page<BasDict> page=new Page<>(pageNo,pageSize);
        //组装过滤条件 动态sql
        QueryWrapper<BasDict> qw=new QueryWrapper();
        qw.like(dictType!=null&&!"".equals(dictType),"dict_type",dictType);
        qw.like(dictItem!=null&&!"".equals(dictItem),"dict_item",dictItem);
        //调用分页方法
        IPage<BasDict> dictPage=basDictMapper.selectPage(page, qw);
        //返回分页对象
        return dictPage;
    }

    @Override
    public void addDict(BasDict basDict) {
        basDictMapper.insert(basDict);
    }

    @Override
    public BasDict getDict(Long id) {
        return basDictMapper.selectById(id);
    }

    @Override
    public void updateDict(BasDict basDict) {
        basDictMapper.updateById(basDict);
    }

    @Override
    public void deleteDict(Long id) {
        basDictMapper.deleteById(id);
    }
}
